import { createMemoryHistory, createWebHistory, createRouter } from 'vue-router'
import { useUserStore } from "@/pinia";
// import Cookies from 'js-cookie';
import { AllManageRouter } from './AllManageRouter';

const routes = [
    {
        path: '/',
        redirect: '/login',
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/view/Login/index.vue'),
        meta: {
            title: '登录',
            requiresAuth: false
        },
    },
    {
        path: '/default',
        name: 'default',
        component: () => import('@/view/dashboard/index.vue'),
        meta: { title: '', requiresAuth: true },
        children: [
            {
                path: '/default/check_mode',
                name: 'check_mode',
                meta: { title: '检查模式' },
                component: () => import('@/view/CheckMode/index.vue'),
                children: [
                    {
                        path: 'customer_info',
                        name: 'customer_info',
                        component: () => import('@/view/CheckMode/CustomerInfo/index.vue'),
                        meta: {
                            title: '客户信息',
                            requiresAuth: true
                        }
                    },
                    {
                        path: 'face_scan',
                        name: 'face_scan',
                        component: () => import('@/view/CheckMode/FaceScan/index.vue'),
                        meta: {
                            title: '人脸扫描',
                            requiresAuth: true
                        }
                    },
                    {
                        path: 'optometrist',
                        name: 'optometrist',
                        component: () => import('@/view/CheckMode/Optometrist/index.vue'),
                        meta: {
                            title: '配镜试戴',
                            requiresAuth: true
                        }
                    },
                    {
                        path: 'try_in_3D',
                        name: 'try_in_3D',
                        component: () => import('@/view/CheckMode/TryIn3D/index.vue'),
                        meta: {
                            title: '试戴3D',
                            requiresAuth: true
                        }

                    }
                ]
            },
            {
                path: '/default/manage_mode',
                name: 'manage_mode',
                component: () => import('@/view/ManageMode/index.vue'),
                meta: { title: '管理模式', requiresAuth: true },
                children: AllManageRouter
            }
        ]
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

router.afterEach((to, from) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
})

export default router